package me.zhengjie.modules.gis.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.gis.service.dto.LineDto;
import me.zhengjie.modules.gis.service.dto.ReceivingDto;
import me.zhengjie.modules.gis.service.dto.RecyclingDto;
import me.zhengjie.modules.gis.service.dto.ReduceEmissionDto;
import me.zhengjie.modules.gis.service.TransportationInHistoryService;
import me.zhengjie.modules.gis.service.TransportationOutHistoryService;
import me.zhengjie.modules.gis.service.impl.GisService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Api(tags = "可视化系统统计数据接口")
@RequestMapping("/api/statistic")
public class GisVisualizeController {

    private final GisService gisService;

    @GetMapping("/getGisReceiving")
    @Log("收运中转数据统计")
    @ApiOperation("收运中转数据统计")
    public ReceivingDto getGisReceiving(Integer year) {
        return gisService.getGisReceiving(year);
    }

    @GetMapping("/getGisRecycling")
    @Log("循环应用数据统计")
    @ApiOperation("循环应用数据统计")
    public RecyclingDto getGisRecycling(Integer year) {
        return gisService.getGisRecycling(year);
    }

    @GetMapping("/getGisRecyclingV2")
    @Log("循环应用数据统计")
    @ApiOperation("循环应用数据统计V2")
    public Object getGisRecyclingV2(Integer year) {
        return gisService.getCache("recycle");
    }

    @GetMapping("/getGisReduceEmission")
    @Log("减量排放数据统计")
    @ApiOperation("减量排放数据统计")
    public ReduceEmissionDto getGisReduceEmission(Integer year) {
        return gisService.getGisReduceEmission(year);
    }

    @GetMapping("/syncWeighbridgeData")
    @Log("立即同步MES地磅地理信息数据")
    @ApiOperation("立即同步MES地磅地理信息数据")
    public ResponseEntity<Object> syncWeighbridgeData() {
        gisService.syncWeighbridgeData();
        return new ResponseEntity<>("同步请求成功，已在后台异步执行，短时间内请勿重复操作", HttpStatus.OK);
    }

    @GetMapping("/syncLineData")
    @Log("立即同步MES特殊地点的路径数据")
    @ApiOperation("立即同步MES特殊地点的路径数据")
    public ResponseEntity<Object> syncLineData() {
        gisService.syncLineData();
        return new ResponseEntity<>("同步请求成功，已在后台异步执行，短时间内请勿重复操作", HttpStatus.OK);
    }

    @GetMapping("/retrieveLatestLines")
    @Log("获取最近的路线数据")
    @ApiOperation("获取最近一段时间的路线数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value ="路线类型 0:出料 1:进料",paramType = "query", dataType="Integer", required = true),
            @ApiImplicitParam(name = "count",value ="最多获取的路线数量",paramType = "query", dataType="Integer", defaultValue= "10"),
            @ApiImplicitParam(name = "days",value ="要获取的天数 days=1为获取当天的",paramType = "query", dataType="Integer", defaultValue= "1")
    })
    public List<LineDto> retrieveLatestLines(Integer type, Integer count, Integer days) {
        return gisService.retrieveLatestLines(type, count, days);
    }

    @GetMapping("/retrieveChangzhouLines")
    @Log("获取常州的运输路线数据")
    @ApiOperation("获取常州的运输路线数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value ="路线类型 0:出料 1:进料",paramType = "query", dataType="Integer", required = true),
            @ApiImplicitParam(name = "count",value ="最多获取的路线数量",paramType = "query", dataType="Integer", defaultValue= "10"),
            @ApiImplicitParam(name = "days",value ="要获取的天数 days=1为获取当天的",paramType = "query", dataType="Integer", defaultValue= "1")
    })
    public List<LineDto> retrieveChangzhouLines(Integer type, Integer count, Integer days) {
        return gisService.retrieveChangzhouLines(type, count, days);
    }

    @GetMapping("/retrieveTransArea")
    @Log("同步事业部地磅数据的点位信息")
    @ApiOperation("同步事业部地磅数据的点位信息")
    public ResponseEntity<Object> retrieveTransArea() {
        gisService.retrieveTransArea();
        return new ResponseEntity<>("同步请求成功，已在后台异步执行，短时间内请勿重复操作", HttpStatus.OK);
    }
}
